﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;

namespace TCHSHue.Modules.IndexControl.BieuMau
{
    public partial class ctrBieuMau : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                NapDanhSachTaiLieu();
        }
        protected void RedirectEdit(object sender, CommandEventArgs e)
        {
            var tl = TaiLieuBLL.getTaiLieu(e.CommandArgument.ToString());
            if (tl != null)
            {
                if (tl.url.Contains(".xlsx"))
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                else if (tl.url.Contains(".xls"))
                    Response.ContentType = "application/vnd.ms-excel";
                else if (tl.url.Contains(".docx"))
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                else if (tl.url.Contains(".doc"))
                    Response.ContentType = "application/msword";
                else if (tl.url.Contains(".pdf"))
                    Response.ContentType = "application/pdf";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + tl.url);
                Response.WriteFile(Server.MapPath("~/Upload/Document_Image/Document/") + tl.url);
            }
        }
        void NapDanhSachTaiLieu()
        {
            var ls = TaiLieuBLL.getList();
            gridBieuMau.DataSource = ls;
            gridBieuMau.DataBind();
        }

        protected void bntTimKiem_Click(object sender, EventArgs e)
        {
            var ls = TaiLieuBLL.getList(txtTimKiem.Text);
            gridBieuMau.DataSource = ls;
            gridBieuMau.DataBind();
        }
    }
}